package com.csoa.community.requests;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import android.util.Log;

import com.csoa.community.bean.AttachBean;
import com.csoa.community.bean.EmailBean;
import com.csoa.community.net.ErrorMsg;
import com.csoa.community.singletons.GlobalVars;
import com.csoa.community.utils.Json;
import com.csoa.community.utils.StringUtils;

public class EmailDetailRequest extends AbstractRequest {

	public EmailBean emailBean;
	
	public EmailDetailRequest(List<BasicNameValuePair> requestValues) {
		super(EMAIL_DETAIL_METHOD, requestValues,GlobalVars.serviceEmailURL,GlobalVars.soapEmailAction);
	}

	

	@Override
	protected void parseRemaingInfo(String json) throws ErrorMsg, JSONException {
		if(!StringUtils.isEmpty(json)) {
			Log.i("msg", json);
//			String stadard = json.replace("[", "").replace("]", "");
			Json detailJson = new Json(json);
			emailBean = new EmailBean();
			emailBean.MessageID = detailJson.getString("MessageID");
			emailBean.Sender = detailJson.getString("Sender");
			emailBean.SentTo = detailJson.getString("SentTo");
			emailBean.Subject = detailJson.getString("Subject");
			emailBean.Date = detailJson.getString("Date");
			emailBean.Size = detailJson.getString("Size");
			emailBean.IsNewMsg = detailJson.getBoolean("IsNewMsg");
			emailBean.BodyHtml = detailJson.getString("BodyHtml");
			emailBean.Cc = detailJson.getString("Cc");
			String attachJson = detailJson.getString("Attachments");
			if(!StringUtils.isEmpty(attachJson)) {
				String [] attachs = attachJson.split(",");
				emailBean.Attachments = new ArrayList<AttachBean>();
				for(int i=0;i<attachs.length;i++) {
					AttachBean attach = new AttachBean();
					attach.FileName = attachs[i];
					attach.FileExtend = attach.FileName.substring(attach.FileName.lastIndexOf("."), attach.FileName.length());
					emailBean.Attachments.add(attach);
				}
				
			}
			
			
		}
		
	}
	
	
	
}
